package indigo.modules
{
	import indigo.collections.ArrayList;
	import indigo.collections.IEnumerator;
	
	internal class ModulesManagerImpl
	{
		private var _modules:ArrayList;
		
		public function get modules():Array {
			return _modules.arrayTo();
		}
		
		public function get numModules():uint {
			return _modules.count;
		}
		
		public function ModulesManagerImpl()
		{
			_modules = new ArrayList();
		}

		public function addModule(module:ModuleInfo):void {
			if(!_modules.contains(module)) {
				_modules.add(module);
			}	
		}
		
		// TODO: study memory
		public function clear():void {
			_modules.clear();
		}
		
		public function getModuleByName(moduleName:String):ModuleInfo {
			var e:IEnumerator = _modules.getEnumerator();
			while(e.moveNext()) {
				if(ModuleInfo(e.current).moduleName == moduleName)
					return e.current as ModuleInfo;
			}
			return null;
		}
	}
}